lines(hes9$PCA1, predict(ab.mod4))
AICc(ab.mod4, second.ord=TRUE)
#so quadratic best. check residuals etc
par(mfrow=c(2,2))
plot(ab.mod3)
#now richness
par(mfrow=c(1,1))
plot(hes9$PCA1, hes9$richness)
#better log10 richness
logrich<-log10(hes9$richness)
plot(hes9$PCA1, logrich)
ri.mod1<-lm(logrich~hes9$PCA1+hes9$PCA2+hes9$PCA3+hes9$PCA4)
summary(ri.mod1)
library(MuMIn)
mms1<-dredge(ri.mod1)
mms1
detach("package:MuMIn", unload = TRUE)
#look at PC1 model
ri.mod2<-lm(logrich~hes9$PCA1)
summary(ri.mod2)
plot(hes9$PCA1,logrich)
lines(hes9$PCA1, predict(ri.mod2))
AICc(ri.mod2, second.ord=TRUE)
#now compare linear and quadratic and cubic models
ri.mod3<-lm(logrich~hes9$PCA1+PCA12)
summary(ri.mod3)
plot(hes9$PCA1,logrich)
lines(hes9$PCA1, predict(ri.mod3))
AICc(ri.mod3, second.ord=TRUE)
#so quadratic better, now cubic
ri.mod4<-lm(logrich~hes9$PCA1+PCA12+PCA13)
summary(ri.mod4)
plot(hes9$PCA1,logrich)
lines(hes9$PCA1, predict(ri.mod4))
AICc(ri.mod4, second.ord=TRUE)
#quadratic best: check residuals etc
par(mfrow=c(2,2))
plot(ri.mod3)
#now log10invsim
par(mfrow=c(1,1))
plot(hes9$PCA1, hes9$invsim)
#better log10 invsim
loginvsim<-log10(hes9$invsim)
plot(hes9$PCA1, loginvsim)
is.mod1<-lm(loginvsim~hes9$PCA1+hes9$PCA2+hes9$PCA3+hes9$PCA4)
summary(is.mod1)
library(MuMIn)
mms1<-dredge(is.mod1)
mms1
detach("package:MuMIn", unload = TRUE)
#look at PC1 model
is.mod2<-lm(loginvsim~hes9$PCA1)
summary(is.mod2)
plot(hes9$PCA1,loginvsim)
lines(hes9$PCA1, predict(is.mod2))
AICc(is.mod2, second.ord=TRUE)
#now compare linear and quadratic and cubic models
is.mod3<-lm(loginvsim~hes9$PCA1+PCA12)
summary(is.mod3)
plot(hes9$PCA1,loginvsim)
lines(hes9$PCA1, predict(is.mod3))
AICc(is.mod3, second.ord=TRUE)
#so linear better: check residuals
par(mfrow=c(2,2))
plot(is.mod2)
#looks good
#look at model of both PC1 and PC2
is.mod4<-lm(loginvsim~hes9$PCA1+hes9$PCA2)
summary(is.mod4)
#now shannon
par(mfrow=c(1,1))
plot(hes9$PCA1, hes9$shannon)
sh.mod1<-lm(hes9$shannon~hes9$PCA1+hes9$PCA2+hes9$PCA3+hes9$PCA4)
summary(sh.mod1)
library(MuMIn)
mms1<-dredge(sh.mod1)
mms1
detach("package:MuMIn", unload = TRUE)
#look at PC1 model
sh.mod2<-lm(hes9$shannon~hes9$PCA1)
summary(sh.mod2)
plot(hes9$PCA1,hes9$shannon)
lines(hes9$PCA1, predict(sh.mod2))
AICc(sh.mod2, second.ord=TRUE)
#now compare linear and quadratic models
sh.mod3<-lm(hes9$shannon~hes9$PCA1+PCA12)
summary(sh.mod3)
plot(hes9$PCA1,hes9$shannon)
lines(hes9$PCA1, predict(sh.mod3))
AICc(sh.mod3, second.ord=TRUE)
#so linear better: check residuals
par(mfrow=c(2,2))
plot(sh.mod2)
#looks good
#look at model with PC1 and PC2
sh.mod4<-lm(hes9$shannon~hes9$PCA1+hes9$PCA2)
summary(sh.mod4)
#now NMDS at trap level
hes10<- read.table("Trap level data.csv", header=TRUE, row.names="Site", sep=",", check.names = FALSE)
trapnmds<-metaMDS(hes10)
trapnmds
par(mfrow=c(1,1))
plot(trapnmds)
plot(trapnmds, type = "n")
text(trapnmds, display = "sites", cex = 0.8, pch=21, col="red", bg="yellow")
text(trapnmds, display = "spec", cex=0.7, col="blue")
scores(sitenmds)
write.csv(scores(sitenmds, display = "sites"), "trapNMDSsitescores.csv")
write.csv(scores(sitenmds, display="species"), "trapNMDSspeciescores.csv")
#need to create nice figure of the biplot
#first make a dataframe of the site scores
nmds.scores <- as.data.frame(scores(trapnmds, display="sites"))  #Using the scores function from vegan to extract the site scores and convert to a data.frame
nmds.scores$site <- rownames(nmds.scores)  # create a column of site names, from the rownames of data.scores
head(nmds.scores)
#now make dataframe of the species scores
species.scores <- as.data.frame(scores(trapnmds, "species"))  #Using the scores function from vegan to extract the species scores and convert to a data.frame
species.scores$species <- rownames(species.scores)  # create a column of species, from the rownames of species.scores
head(species.scores)
FigS1<-ggplot() +
geom_text(data=species.scores,aes(x=NMDS1,y=NMDS2,label=species),size=3, fontface = "italic", alpha=0.5) +  # add the species labels
geom_point(data=nmds.scores,aes(x=NMDS1,y=NMDS2),size=2) + # add the point markers
geom_text(data=nmds.scores,aes(x=NMDS1,y=NMDS2,label=site),size=5,vjust=0,hjust=0) +  # add the site labels
scale_y_continuous(breaks = seq(-1.5, 1.5, by = 0.5))+
scale_x_continuous(breaks = seq(-2, 2, by = 0.5), limits=c(-2,2))+
coord_equal() +
theme_bw() +
theme(
panel.background = element_blank(),
panel.grid.major = element_blank(),  #remove major-grid labels
panel.grid.minor = element_blank(),  #remove minor-grid labels
plot.background = element_blank())
FigS1
ggsave("FigS1.tiff", units="cm", width=20, height=15, dpi=300, compression = 'lzw')
#now models of NMDS against PCs at trap level
par(mfrow=c(1,1))
plot(hes9$PCA1, hes9$NMDS1)
nmds.mod1<-lm(NMDS1~PCA1+PCA2+PCA3+PCA4, data=hes9)
summary(nmds.mod1)
library(MuMIn)
mms1<-dredge(nmds.mod1)
mms1
detach("package:MuMIn", unload = TRUE)
#now get the best model
nmds.mod2<-lm(hes9$NMDS1~hes9$PCA1+hes9$PCA3+hes9$PCA4)
summary(nmds.mod2)
#check residuals etc
par(mfrow=c(2,2))
plot(nmds.mod2)
#looks fine now NMDS2
par(mfrow=c(1,1))
plot(hes9$PCA1,hes9$NMDS2)
nmds.mod3<-lm(NMDS2~PCA1+PCA2+PCA3+PCA4, data=hes9)
summary(nmds.mod3)
library(MuMIn)
mms1<-dredge(nmds.mod3)
mms1
detach("package:MuMIn", unload = TRUE)
#try PCA2 model
nmds.mod4<-lm(NMDS2~PCA2, data=hes9)
summary(nmds.mod4)
#now figure of PCA1 v NMDS1
cleanup=theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(color = "black"),
axis.line.x.top = element_line(color = "black"),
axis.line.y.right = element_line(color = "black"))
FigS2=ggplot(hes9, aes(PCA1, NMDS1))+
geom_point()+
xlab("PC1")+
ylab("NMDS1")+
coord_cartesian(ylim=c(-1.5,1.5)) +
geom_smooth(method=lm, color="black", fullrange=FALSE)+
scale_y_continuous(breaks = seq(-1.5, 1.5, by = 0.5))+
scale_x_continuous(breaks = seq(-2.5, 2.5, by = 0.5), limits=c(-2.5,2.5))+
cleanup
FigS2
ggsave("FigureS2.tiff", units="cm", width=20, height=15, dpi=300, compression = 'lzw')
#now models of sites against vegetation variables including elevation.
alt1<-read.table("site level summary.csv", header=TRUE, sep=",")
names(alt1)
e2<-alt1$elevation^2
e3<-alt1$elevation^3
e4<-alt1$elevation^4
mod1<-lm(alt1$Total.site.abundance~alt1$elevation +e2 +e3
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod1)
library(MuMIn)
mms10<-dredge(mod1, fixed = c("alt1$elevation", "e2", "e3"))
mms10
detach("package:MuMIn", unload = TRUE)
#best model only with elevation terms, none other close
#now log richness
logrich<-log10(alt1$Total.site.richness)
mod2<-lm(logrich~alt1$elevation +e2
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod2)
library(MuMIn)
mms11<-dredge(mod2, fixed = c("alt1$elevation", "e2"))
mms11
#again best model just with elevation terms
#look at other models
mod21<-lm(logrich~alt1$elevation +e2
+ alt1$Fern.ground.cover)
summary(mod21)
mod22<-lm(logrich~alt1$elevation +e2
+alt1$herb.ground.cover )
summary(mod22)
#now log invsim
loginv<-log10(alt1$invsim)
mod3<-lm(loginv~alt1$elevation
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod3)
mms12<-dredge(mod3, fixed = c("alt1$elevation"))
mms12
#best model with elevation and herbs, none others were close
#look at this model
mod3b<-lm(loginv~alt1$elevation
+alt1$herb.ground.cover)
summary(mod3b)
mod4<-lm(alt1$shannon~alt1$elevation +e2
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod4)
mms13<-dredge(mod4, fixed = c("alt1$elevation","e2"))
mms13
#best model again with elevation and herb ground cover
#look at this model
mod41<-lm(alt1$shannon~alt1$elevation +e2
+alt1$herb.ground.cover )
summary(mod41)
#now NMDS1
mod5<-lm(alt1$NMDS1~alt1$elevation
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod5)
mms14<-dredge(mod5, fixed = c("alt1$elevation"))
mms14
plot(alt1$elevation, alt1$NMDS1)
#looks linear
#look at best model
mod51<-lm(alt1$NMDS1~alt1$elevation
+ alt1$Total.epiphytes
)
summary(mod51)
#now models without elevation
#start with abundance.
mod6<-lm(alt1$Total.site.abundance~
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod6)
mms15<-dredge(mod6)
summary(model.avg(mms15, subset = delta <= 2))
#now log richness
mod7<-lm(logrich~
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod7)
mms16<-dredge(mod7)
mms16
summary(model.avg(mms16, subset = delta <= 2))
#plot best model
plot(alt1$Total.lianas, logrich)
#now log invsim
mod8<-lm(loginv~
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod8)
mms17<-dredge(mod8)
mms17
summary(model.avg(mms17, subset = delta <= 2))
plot(alt1$herb.ground.cover, loginv)
#now shannon
mod10<-lm(alt1$shannon~
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod10)
mms18<-dredge(mod10)
mms18
summary(model.avg(mms18, subset = delta <= 2))
#plot best predictor
plot(alt1$Total.epiphytes, alt1$shannon)
#now NMDS1
mod11<-lm(alt1$NMDS1~
+alt1$N.plants.DBH...10cm
+alt1$N.plants.DBH..10cm + alt1$N.Palm.trees + alt1$N.Fern.trees
+alt1$Bamboo.ground.cover+ alt1$Fern.ground.cover
+alt1$herb.ground.cover + alt1$Total.epiphytes
+alt1$Total.lianas)
summary(mod11)
mms19<-dredge(mod11)
mms19
summary(model.avg(mms19, subset = delta <= 2))
#plot best predictor
plot(alt1$Bamboo.ground.cover, alt1$NMDS1)
#now trap level models
alt2<-read.table("trap level summary data.csv", header=TRUE, sep=",")
names(alt2)
e2<-alt2$elevation^2
e3<-alt2$elevation^3
#first models constrained to include elevation
#for abundance includes e2 and e3
mod12<-lm(alt2$Total.abundance~alt2$elevation +e2 +e3
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod12)
mms20<-dredge(mod12, fixed = c("alt2$elevation", "e2", "e3"))
mms20
summary(model.avg(mms20, subset = delta <= 2))
#now log richness, contrained with e and e2
logrich<-log10(alt2$Total.trap.richness)
mod13<-lm(logrich~alt2$elevation +e2
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod13)
mms21<-dredge(mod13, fixed = c("alt2$elevation", "e2"))
mms21
summary(model.avg(mms21, subset = delta <= 2))
#plot best predictor
plot(alt2$total.epiphytes, logrich)
#now log invsim with e and e2
loginv<-log10(alt2$Invsim)
mod14<-lm(loginv~alt2$elevation +e2
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod14)
mms22<-dredge(mod14, fixed = c("alt2$elevation", "e2"))
mms22
summary(model.avg(mms22, subset = delta <= 2))
#plot best predictors
plot(alt2$total.epiphytes, loginv)
plot(+alt2$herb.ground.cover, loginv)
#now shannon, with e and e2
mod15<-lm(alt2$shannon~alt2$elevation +e2
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod15)
mms23<-dredge(mod15, fixed = c("alt2$elevation", "e2"))
mms23
summary(model.avg(mms23, subset = delta <= 2))
#plot best predictors
plot(alt2$total.epiphytes, alt2$shannon)
plot(+alt2$herb.ground.cover, alt2$shannon)
# now NMDS1 with elevation
mod16<-lm(alt2$NMDS1~alt2$elevation
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod16)
mms24<-dredge(mod16, fixed = c("alt2$elevation"))
mms24
summary(model.avg(mms24, subset = delta <= 2))
#plot best predictor
plot(alt2$total.epiphytes, alt2$NMDS1)
#now models of trap level without elevation
#start with abundance.
mod17<-lm(alt2$Total.abundance~
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod17)
mms25<-dredge(mod17)
mms25
summary(model.avg(mms25, subset = delta <= 2))
#now log richness
logrich<-log10(alt2$Total.trap.richness)
mod18<-lm(logrich~
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod18)
mms26<-dredge(mod18)
mms26
summary(model.avg(mms26, subset = delta <= 2))
#plot best predictor
plot(alt2$total.epiphytes, logrich)
#now log invsimp
loginv<-log10(alt2$Invsim)
mod19<-lm(loginv~
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod19)
mms27<-dredge(mod19)
mms27
summary(model.avg(mms27, subset = delta <= 2))
summary(model28)
par(mfrow=c(2,2))
plot(model28)
#looks great
#now shannon
mod20<-lm(alt2$shannon~
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod20)
mms29<-dredge(mod20)
mms29
summary(model.avg(mms29, subset = delta <= 2))
#now NMDS1
mod21<-lm(alt2$NMDS1~
+alt2$N.plants.DBH...10cm
+alt2$N.plants.DBH..10cm + alt2$N.Palm.trees + alt2$N.Fern.trees
+alt2$Bamboo.ground.cover+ alt2$Fern.ground.cover
+alt2$herb.ground.cover + alt2$total.epiphytes
+alt2$total.lianas)
summary(mod21)
mms30<-dredge(mod21, fixed = c("alt2$elevation"))
mms30
summary(model.avg(mms30, subset = delta <= 2))
#set theme
cleanup=theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(color = "black"),
axis.line.x.top = element_line(color = "black"),
axis.line.y.right = element_line(color = "black"))
#create table of log richness and epiphytes
fig8atab<-data.frame(alt2$total.epiphytes, logrich)
plot(alt2$total.epiphytes, logrich)
Fig8a = ggplot(fig8atab, aes(alt2$total.epiphytes, logrich))+
geom_point()+
xlab("Epiphyte density")+
ylab(bquote(Log[10]~'Richness'))+
scale_y_continuous(breaks = seq(0, 1.5, by = 0.5))+
scale_x_continuous(breaks = seq(0, 20, by = 5), limits=c(0,20))+
cleanup
#now invsim against herbs
Fig8btab<-data.frame(alt2$herb.ground.cover, loginv)
plot(alt2$herb.ground.cover, loginv)
Fig8b = ggplot(Fig8btab, aes(alt2$herb.ground.cover, loginv))+
geom_point()+
xlab("Herb ground cover")+
ylab(bquote(Log[10] (1/D)))+
scale_y_continuous(breaks = seq(0, 1.4, by = 0.2), limits = c(0, 1.4))+
scale_x_continuous(breaks = seq(0, 3, by = 0.5), limits=c(0,3))+
cleanup
plot(alt2$total.epiphytes, alt2$shannon)
Fig8c = ggplot(alt2, aes(alt2$total.epiphytes, alt2$shannon))+
geom_point()+
xlab("Epiphyte density")+
ylab("Shannon diversity")+
scale_y_continuous(breaks = seq(0, 3.5, by = 0.5), limits = c(0, 3.5))+
scale_x_continuous(breaks = seq(0, 20, by = 5), limits=c(0,20))+
cleanup
#now bamboo against NMDS1
plot(alt2$Bamboo.ground.cover, alt2$NMDS1)
Fig8d = ggplot(alt2, aes(alt2$Bamboo.ground.cover, alt2$NMDS1))+
geom_point()+
xlab("Bamboo ground cover")+
ylab("NMDS1")+
scale_y_continuous(breaks = seq(-1.5, 2, by = 0.5), limits=c(-1.5, 2))+
scale_x_continuous(breaks = seq(0, 3, by = 0.5), limits=c(0,3))+
cleanup
Figure8<-ggarrange(Fig8a, Fig8b, Fig8c, Fig8d,
labels = c("(a)", "(b)", "(c)", "(d)"),
hjust=0,
ncol = 2, nrow = 2)
Figure8
ggsave("Figure8.tiff", units="cm", width=20, height=15, dpi=300, compression = 'lzw')
